/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Admin_Add.java
 *
 * Created on Oct 19, 2010, 3:42:01 PM
 */

package cat20032010;

import java.sql.*;
import java.util.logging.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Daniel Tan
 */
public class Admin_Add extends javax.swing.JFrame {
    Statement stmt;
    private ResultSet rset;
    static public String newordername,newordercode,neworderprice;
    /** Creates new form Admin_Add */
    public Admin_Add() {
        initComponents();
        setLocationRelativeTo(null);
    }
    public void reset(){
        menucode.setText("");
        menuname.setText("");
        menuprice.setText("");
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        menuname = new javax.swing.JTextField();
        menuprice = new javax.swing.JTextField();
        menucode = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setText(" Add Menu List");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(165, 25, 176, 42);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("RM");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(220, 190, 30, 30);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Menu Code");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(70, 110, 100, 30);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Menu Name");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(70, 150, 100, 30);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel5.setText("Menu Price");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(70, 190, 100, 30);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel6.setText(":");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(170, 110, 40, 30);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel7.setText(":");
        jPanel1.add(jLabel7);
        jLabel7.setBounds(170, 150, 40, 30);
        jPanel1.add(menuname);
        menuname.setBounds(220, 150, 190, 30);
        jPanel1.add(menuprice);
        menuprice.setBounds(250, 190, 160, 30);
        jPanel1.add(menucode);
        menucode.setBounds(220, 110, 190, 30);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/OK.png"))); // NOI18N
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setDefaultCapable(false);
        jButton1.setFocusPainted(false);
        jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/OKMouseOver.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(250, 300, 120, 60);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button/BACK.png"))); // NOI18N
        jButton2.setBorderPainted(false);
        jButton2.setContentAreaFilled(false);
        jButton2.setDefaultCapable(false);
        jButton2.setFocusPainted(false);
        jButton2.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/button/BACKMouseOver.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(377, 300, 130, 60);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel8.setText(":");
        jPanel1.add(jLabel8);
        jLabel8.setBounds(170, 190, 40, 30);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 520, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int reply = JOptionPane.showConfirmDialog(null, "Confirm Cancel Adding Menu?", "Confirm", JOptionPane.YES_NO_OPTION);
        if (reply == JOptionPane.YES_OPTION){
            dispose();
            reset();
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        if (menucode.getText().equals(""))
            JOptionPane.showMessageDialog(null, "Menu Code is not filled", "Error!", JOptionPane.ERROR_MESSAGE);
        else if (menuname.getText().equals(""))
            JOptionPane.showMessageDialog(null, "Menu Name is not filled", "Error!", JOptionPane.ERROR_MESSAGE);
        else if (menuprice.getText().equals(""))
            JOptionPane.showMessageDialog(null, "Menu Price is not filled", "Error!", JOptionPane.ERROR_MESSAGE);
        else{
        newordername = menuname.getText();
        newordercode = menucode.getText();
        neworderprice = menuprice.getText();

        addmenu();
        reset();
        dispose();
        Administrator.getdata();
        }
    }//GEN-LAST:event_jButton1ActionPerformed
public void addmenu(){
        try {
            Main.getConnection();
            stmt = Main.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rset = stmt.executeQuery("INSERT INTO MENU(MENU_CODE , MENU_NAME , MENU_PRICE) VALUES ('"+newordercode+"','"+newordername+"','"+neworderprice+"')");
            JOptionPane.showMessageDialog(null, "Data Insert Success", "Success!", JOptionPane.INFORMATION_MESSAGE);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Data Insert Fail", "Fail!", JOptionPane.ERROR_MESSAGE);
            Logger.getLogger(Administrator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Admin_Add().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField menucode;
    private javax.swing.JTextField menuname;
    private javax.swing.JTextField menuprice;
    // End of variables declaration//GEN-END:variables

}
